//#CLIENTSIDE
function onCreated(){
  setarray(this.firex,50);
  setarray(this.firey,50);
  setarray(this.fdx,50);
  setarray(this.fdy,50);
  setarray(this.time,50);
  setarray(this.timea,50); 
  
  setarray(this.fx,50);
  setarray(this.fy,50);
  setarray(this.ffdx,50);
  setarray(this.ffdy,50);
  setarray(this.ftime,50);
  setarray(this.ftimea,50);
  setarray(this.fz,50); 
}
public function onCatchFire(){
  this.size=20;
  this.dam=0;
  this.catch=1;
  for(temp.n=0;temp.n<50;temp.n++){
    this.time[n]=int(random(0,80));
    this.timea[n]=10;
    this.firex[n]=-5;
    this.firey[n]=-5;
    this.fdx[n]=int(random(1,8))/100;
    this.fdy[n]=int(random(5,12))/100;
  }
  for(temp.n=0;temp.n<50;temp.n++){
    this.ftime[n]=int(random(0,40));
    this.ftimea[n]=10;
    this.fz[n]=int(random(0,4));
    if (n<this.size/2){
      this.fx[n]=int(random(-20,100))/100;
      this.fy[n]=int(random(-60,100))/100;
    }else{
      this.fx[n]=int(random(-20,100))/100+playerx;
      this.fy[n]=int(random(-60,100))/100+playery;      
    }
    this.ffdx[n]=int(random(1,6))/100;
    this.ffdy[n]=int(random(2,8))/100;
  }
  onTimeout();
}


function onTimeout(){
  ///////////////////////Smoke
  temp.aa=0;
  for(temp.n=0;temp.n<this.size+10;temp.n++){
    if (this.time[n]<=0 && this.catch==1){
      this.time[n]=int(random(20,40));
      this.timea[n]=10;
      this.firex[n]=int(random(-50,130))/100+playerx;
      this.firey[n]=int(random(-50,70))/100+playery;
      this.fdx[n]=int(random(1,8))/100;
      this.fdy[n]=int(random(5,12))/100;
    }
    this.time[n]=this.time[n]-1;
    if (this.timea[n]>0){
      this.timea[n]=this.timea[n]-1;
    }
    this.firex[n]=this.firex[n]+this.fdx[n];
    this.firey[n]=this.firey[n]-this.fdy[n];
    showimg(400+n,"frontier_dust2.png",this.firex[n],this.firey[n]);
    temp.fade=this.time[n];
    temp.fade2=this.timea[n];
    with(findimg(400+n)){
      mode=1; alpha=fade/50-fade2/10-aa; zoom=1-fade/300+.4;
      rotation=fade/50;
    }
  }  
  
  ///////////////////////////Fire
  for(temp.n=0;temp.n<this.size;temp.n++){
    if (this.ftime[n]<=0 && this.catch==1){
      this.ftime[n]=int(random(30,40));
      this.ftimea[n]=10;
      this.fz[n]=int(random(0,5));
      if (n<this.size/2){
        this.fx[n]=int(random(-20,100))/100;
        this.fy[n]=int(random(-60,100))/100;
      }else{
        this.fx[n]=int(random(-20,60))/100+playerx;
        this.fy[n]=int(random(-60,100))/100+playery;    
        this.ftime[n]=int(random(20,30));  
        this.fz[n]=1;
      }
      this.ffdx[n]=int(random(1,6))/100;
      this.ffdy[n]=int(random(2,8))/100;
      if (player.dir==3){
        this.ffdx[n]=int(random(-6,-1))/100;        
      }
    }
    this.fx[n]=this.fx[n]+this.ffdx[n];
    this.fy[n]=this.fy[n]-this.ffdy[n];
    this.ftime[n]=this.ftime[n]-1;
    if (this.ftimea[n]>0){
      this.ftimea[n]=this.ftimea[n]-1;
    }
    if (n<this.size/2){
      showimg(400+n,"firesl.gif",this.fx[n]+playerx,this.fy[n]+playery);
    }else{
      showimg(400+n,"firesl.gif",this.fx[n],this.fy[n]);    
    }
    temp.a=this.ftime[n];
    temp.b=this.ftimea[n];
    with(findimg(300+n)){
      mode=1; alpha=a/30-b/10-aa;
    }
    if (this.fz[n]==0){
      with(findimg(300+n)){
        this.zoom=1-a/60;
      }
    }else{
      with(findimg(300+n)){
        this.zoom=a/60;
      }
    }
  }
  //////////////////////////Taking Damage
  if (player.ani!="swim" && player.hp>0 && this.catch==1){
    if (this.dam>0){
      this.dam--;
    }
    if (this.dam<=0){
      this.dam=50;
      player.hp=player.hp-0.5; 
    }
  }else{
    this.catch=0;
  }
  settimer(0.05);
}
